/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package rosedb.gui;

import com.explodingpixels.macwidgets.HudWidgetFactory;
import com.explodingpixels.macwidgets.HudWindow;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

/**
 *
 * @author riu
 */
public class AddRoseDialog extends HudWindow{

    private MainFrame gui;
    private JPanel contentPane = new JPanel(new BorderLayout(0, 5));
    private JButton btn_ok;
    private JTextField txt_name;
    private String message;
    private String name;
    private boolean disposed = false;

    public AddRoseDialog(String m, MainFrame gui) {
        super("Rose Hinzufügen", gui);
        message = m;
        setContentPane(contentPane);
        getJDialog().setSize(300, 100);
        getJDialog().setModal(true);
        getJDialog().setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        init();
        getJDialog().setLocation(gui.getX()+gui.getWidth()/2-getJDialog().getWidth()/2, gui.getY()+gui.getHeight()/2-getJDialog().getHeight()/2);
        getJDialog().setVisible(true);
    }

    public String getName() {
        return name;
    }

    private void init(){
        btn_ok = HudWidgetFactory.createHudButton("Ok");
        btn_ok.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                name = txt_name.getText().trim();
                AddRoseDialog.this.getJDialog().setVisible(false);
            }
        });

        txt_name = HudWidgetFactory.createHudTextField("");
        txt_name.setHorizontalAlignment(JTextField.CENTER);
        txt_name.addKeyListener(new KeyAdapter() {

            @Override
            public void keyTyped(KeyEvent e) {
                if(e.getKeyChar() == '\n'){
                    btn_ok.doClick();
                }
            }
            
        });


        contentPane.add(HudWidgetFactory.createHudLabel(message), BorderLayout.NORTH);
        contentPane.add(txt_name, BorderLayout.CENTER);
        contentPane.add(btn_ok, BorderLayout.SOUTH);
        contentPane.setOpaque(false);
    }


    public void dispose(){
        getJDialog().dispose();
        disposed = true;
    }

    public boolean isDisposed() {
        return disposed;
    }

    
}
